#require 'asymy' # I guess it doesn't HAVE to be loaded before, but hey :)

module Asymy
    class Connection
        # same as exec, except it also returns the args, as well as letting them be processed within the block
        @@total_fibers_waiting = 0
        def exec_and_fiber_yield query
                        fiber = Fiber.current
                        incoming = nil
                        @@total_fibers_waiting += 1
                        print "total fibers waiting: #{@@total_fibers_waiting}\n"
                        self.exec(query) {|*args| yield(*args); incoming = *args; fiber.resume }
                        Fiber.yield # continues when fiber.resume is called, above
                        @@total_fibers_waiting -= 1
                        print "done: total fibers waiting now: #{@@total_fibers_waiting}\n"
                        return incoming
        end
    end
end

